//
//  LegalString.m
//  ArtClouds
//
//  Created by administrator on 15/9/28.
//  Copyright (c) 2015年 lishuai. All rights reserved.
//

#import "LegalString.h"

@implementation LegalString

//限制TextField最长长度，并限制非法字符
+ (BOOL)limitStringTextField:(UITextField *)textField maxLength:(int)length content:(NSString *)content string:(NSString *)string
{
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:content] invertedSet];
    
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
    
    BOOL canChange = [string isEqualToString:filtered];
    
    return textField.text.length >= length ? NO: canChange;
}

@end
